Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document how to support camelcase attributes #417

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

seanpdoyle
Copy link

Generally, this commit adds documentation to the ActiveResource::Base class-level and method-level documentation to explain how attribute loading and encoding works.

In addition, test coverage is added for camelcase-based attribute loading and encoding. Code samples are added to method-level documentation to more clearly communicate how support can be added at the application level.

Generally, this commit adds documentation to the `ActiveResource::Base`
class-level and method-level documentation to explain how attribute
loading and encoding works.

In addition, test coverage is added for camelcase-based attribute
loading and encoding. Code samples are added to method-level
documentation to more clearly communicate how support can be added at
the application level.
Comment on lines +19 to +27
def load(attributes, *args)
attributes = attributes.deep_transform_keys { |key| key.to_s.underscore }

super
end

def serializable_hash(options = {})
super.deep_transform_keys! { |key| key.camelcase(:lower) }
end
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the best way to achieve this outcome? When learning about the library, my first instinct was to tackle name casing at the JsonFormat level.

Unfortunately, since #encode is implemented in terms of #to_json, and not JsonFormat.encode, a custom format that inherited from JsonFormat had no effect.

Is there a more canonical way to extend or configure the pre-existing JsonFormat module to more elegantly handle this?

Could it be worthwhile to explore changing the Base#encode implementation to incorporate self.class.format.encode?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant